package com.huanzhidadi.single.thread.order;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class ThreadCompletableFuture {
    public static void main(String[] args) {
        CompletableFuture<Void> t1 = CompletableFuture.runAsync(() -> {
            System.out.println("线程t1运行");
        });

        CompletableFuture<Void> t2 = t1.thenRun(() -> {
            System.out.println("线程t2运行");
        });

        CompletableFuture<Void> t3 = t2.thenRun(() -> {
            System.out.println("线程t3运行");
        });

        try {
            // 等待所有CompletableFuture完成
            t3.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("主线程完毕");
    }
}
